package com.dianjing.dianjing.controller;


import com.dianjing.dianjing.dto.input.DemandInput;
import com.dianjing.dianjing.dto.input.PublishInput;
import com.dianjing.dianjing.entity.Demand;
import com.dianjing.dianjing.service.DemandService;
import com.dianjing.dianjing.util.DataUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.List;

/**
 * <p>
 * 需求表 前端控制器
 * </p>
 *
 * @author LBG
 * @since 2022-11-09
 */
@RestController
@Api(tags = "需求模块")
@RequestMapping("/demand")
public class DemandController {

    @Resource
    private DemandService demandService;

    @PostMapping("/publishDemand")
    @ApiOperation("发布需求")
    public DataUtils publishDemand(@RequestBody PublishInput input){
        return demandService.publishDemand(input);
    }

    @PostMapping("/showAllDemand")
    @ApiOperation("查看所有需求")
    public DataUtils showAllDemand(@RequestBody DemandInput input){
        return demandService.showAllDemand(input);
    }
    @GetMapping("/showWaitAccept/{userId}")
    @ApiOperation("获取需求方/画师的“待接受”需求")
    public DataUtils showWaitAccept(@PathVariable("userId") Long  userId){
        List<Demand> demands = demandService.getUserWaitAccept(userId);
        return DataUtils.ok(demands);
    }

    @GetMapping("/showWaitResponse")
    @ApiOperation("获取画师能查看的需求大厅-指定类型的待响应")
    public DataUtils showWaitResponse(@RequestParam(value = "type",required = false) Integer type){
        List<Demand> demands = demandService.getWaitResponse(type);
        return DataUtils.ok(demands);
    }

//    @GetMapping("/showWaitCreate/{userId}")
//    @ApiOperation("获取需求方/画师的“待创作”需求")
//    public DataUtils showWaitCreate(@PathVariable("userId") Long  userId){
//        List<Demand> demands = demandService.getUserWaitAccept(userId);
//        return DataUtils.ok(demands);
//    }



    @GetMapping("/selectDemandById/{id}")
    @ApiOperation("根据id查看需求详情")
    public DataUtils selectDemandById(@PathVariable("id") Integer id){
        return demandService.selectDemandById(id);
    }

    @GetMapping("/demandResponse/{demandId}/{painterId}")
    @ApiOperation("需求响应")
    public DataUtils demandRespond(@PathVariable("demandId") Long demandId,@PathVariable("painterId") Long painterId){
        return demandService.demandRespond(demandId,painterId);
    }





    @GetMapping("/refuseDemand/{id}")
    @ApiOperation("拒绝需求")
    public DataUtils refuseDemand(@PathVariable("id") Long id){
        return demandService.refuseDemand(id);
    }

    @PostMapping("/cancelDemand/{userId}/{demandId}")
    @ApiOperation("取消需求")
    public DataUtils cancelDemand(@PathVariable("userId") Long userId,@PathVariable("demandId") Integer demandId){
        Boolean b =  demandService.cancelDemand(userId,demandId);
        if(b) {
            return DataUtils.ok();
        }else  {
            return DataUtils.error("无法取消");
        }
    }
    @PostMapping("/painterRefuse/{userId}/{demandId}")
    @ApiOperation("画师拒绝需求")
    public DataUtils painterRefuse(@PathVariable("userId") Long userId,@PathVariable("demandId") Integer demandId){
        Boolean b =  demandService.painterRefuse(userId,demandId);
        if(b) {
            return DataUtils.ok();
        }else  {
            return DataUtils.error("无法取消");
        }
    }


    @PostMapping("/painterReceive/{userId}/{demandId}")
    @ApiOperation("画师接受需求")
    public DataUtils painterReceive(@PathVariable("userId") Long userId,@PathVariable("demandId") Long demandId){
        Boolean b =  demandService.painterReceive(userId,demandId);
        if(b) {
            return DataUtils.ok();
        }else  {
            return DataUtils.error("无法取消");
        }
    }
}

